package com.acme.bankapp.domain.bank;

import com.acme.bankapp.exceptions.IllegalAmountArgumentException;
import com.acme.bankapp.exceptions.NotEnoughFundsException;

public abstract class AbstractAccount implements Account {

	protected double balance = 0;
	
	public AbstractAccount(double amount) {
		this.balance = amount;
	}

	public double getBalance() {
		return balance;
	}

	public int deposit(double amount) throws IllegalAmountArgumentException {
		if (amount <= 0) {
			throw new IllegalAmountArgumentException(balance-amount); 
		}
		balance += amount;
		return 0;
	}
	
	public int withdraw(double amount) throws IllegalAmountArgumentException, NotEnoughFundsException {
		if (amount <= 0 ) {
			throw new IllegalAmountArgumentException(amount); 
		}
		if (maximumAmountToWithdraw() < amount) {
			throw new NotEnoughFundsException(maximumAmountToWithdraw()-amount);
		}
		
		balance -= amount;
		return 0;
	}
}
